#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
#include <set>
#include <unordered_set>
using ll = int64_t;
#define sl static inline

const ll maxm=1e5+7,p=1e9+7;
ll n,m,v;
struct X{
    ll c,d;
    inline bool operator<(const X& o)const{
        return c<o.c;
    }
}x[maxm];
std::unordered_set<int> s;

sl void solve(){
    s.clear();
    std::cin>>n>>m>>v;
    const ll one = v*v%p;
    const ll both = (one-v+1+p)%p;
    for(ll i=1;i<=m;i++){
        std::cin>>x[i].c>>x[i].d;
        s.insert(x[i].c);
    }
    std::sort(x+1,x+1+m);
    for(ll i=1;i<m;i++){
        if(x[i].c==x[i+1].c && x[i].d!=x[i+1].d){
            std::cout<<"0\n";
            return;
        }
    }
    ll ans=1;
    for(ll i=1;i<n;i++){
        if(s.count(i)&s.count(i+1)){
            ans=ans*both%p;
        }else{
            ans=ans*one%p;
        }
    }
    std::cout<<ans<<"\n";
}

/*
xi yes xi+1 no v*v
xi no xi+1 yes v*v
xi yes xi+1 yes v*v-1
*/

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll t;
    std::cin>>t;
    while(t--){
        solve();
    }
}